package controllers

import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import play.api.db.slick._
import play.api.Play.current
import play.api.libs.json._
// you need this import to have combinators
import play.api.libs.functional.syntax._

import views._
import models._

//postfix operator tupled should be enabled
import scala.language.postfixOps

object Poc extends Controller {

	implicit val rds = (
    (__ \ 'name).read[String] and
    (__ \ 'age).read[Long]
  ) tupled

  def index = Action { 
    Ok(html.poc.index("Hello application"))
  }

  
  def fetch(arg:String) = Action {
  //  Ok(Json.toJson("hello," + arg ))
    // Ok(Json.obj("status" ->"OK", "message" -> ("Hello "+arg) ))
    
    val data = List(
    	/* May 2006 */
			List(1147651200000l,67.79),
			List(1147737600000l,64.98),
			List(1147824000000l,65.26),
			List(1147910400000l,63.18),
			List(1147996800000l,64.51),
			List(1148256000000l,63.38),
			List(1148342400000l,63.15),
			List(1148428800000l,63.34),
			List(1148515200000l,64.33),
			List(1148601600000l,63.55),
			List(1148947200000l,61.22),
			List(1149033600000l,59.77),
			/* Jun 2006 */
			List(1149120000000l,62.17),
			List(1149206400000l,61.66),
			List(1149465600000l,60.00),
			List(1149552000000l,59.72),
			List(1149638400000l,58.56),
			List(1149724800000l,60.76),
			List(1149811200000l,59.24),
			List(1150070400000l,57.00),
			List(1150156800000l,58.33),
			List(1150243200000l,57.61),
			List(1150329600000l,59.38),
			List(1150416000000l,57.56),
			List(1150675200000l,57.20),
			List(1150761600000l,57.47),
			List(1150848000000l,57.86),
			List(1150934400000l,59.58),
			List(1151020800000l,58.83),
			List(1151280000000l,58.99),
			List(1151366400000l,57.43),
			List(1151452800000l,56.02),
			List(1151539200000l,58.97),
			List(1151625600000l,57.27),
			/* Jul 2006 */
			List(1151884800000l,57.95),
			List(1152057600000l,57.00),
			List(1152144000000l,55.77),
			List(1152230400000l,55.40),
			List(1152489600000l,55.00),
			List(1152576000000l,55.65),
			List(1152662400000l,52.96),
			List(1152748800000l,52.25),
			List(1152835200000l,50.67),
			List(1153094400000l,52.37),
			List(1153180800000l,52.90),
			List(1153267200000l,54.10),
			List(1153353600000l,60.50),
			List(1153440000000l,60.72),
			List(1153699200000l,61.42),
			List(1153785600000l,61.93),
			List(1153872000000l,63.87),
			List(1153958400000l,63.40),
			List(1154044800000l,65.59),
			List(1154304000000l,67.96)
			
    )

		Logger.debug("data: %s".format(Json.toJson(data)))
    Ok(Json.toJson(data))

  }

  
}
